<?php
/**
 * 登录授权控制器
 * Date: 2025/08/31
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\BaseController;
use App\Services\Admin\AuthService;
use Illuminate\Http\Request;

class AuthController extends BaseController
{
    /**
     * 获取登录验证码
     * @date 2025/08/31
     * @return \Illuminate\Http\JsonResponse
     */
    public function verifyCode()
    {
        return (new AuthService())->verifyCode();
    }

    /**
     * 管理员登录
     * @date 2025/08/31
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function login(Request $request)
    {
        $params = $this->validate($request, [
            'account' => 'required',
            'password' => 'required',
            'code' => 'required|size:4',
            'token' => 'required'
        ], [
            'account.required' => '账号不能为空',
            'password.required' => '密码不能为空',
            'code.required' => '验证码不能为空',
            'code.size' => '验证码长度必须是4位',
            'token.required' => '验证码token不能为空'
        ]);
        return (new AuthService())->login($params);
    }

    /**
     * 管理员退出登录
     * @date 2025/08/31
     * @return \Illuminate\Http\JsonResponse
     */
    public function loginOut(Request $request)
    {
        return (new AuthService())->loginOut();
    }
}
